package org.jsola.hr.helper;

import org.jsola.hr.constant.EmpInfoRequireType;
import org.jsola.hr.constant.EmpInfoScene;
import org.jsola.hr.dto.EmpWorkRequireAddDTO;
import org.jsola.hr.dto.EmpWorkRequireUpdateDTO;
import org.jsola.hr.entity.EmpWorkRequireDO;
import org.jsola.hr.query.EmpWorkRequireQuery;
import org.jsola.hr.service.IEmpWorkRequireService;
import org.jsola.hr.vo.EmpWorkRequireVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class EmpWorkRequireTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpWorkRequireService empWorkRequireService;

    /**
     * 生成add测试数据
     * @return EmpWorkRequireAddDTO
     */
    public EmpWorkRequireAddDTO getEmpWorkRequireAddDTO(){
        EmpWorkRequireAddDTO empWorkRequireAddDTO = new EmpWorkRequireAddDTO();
        empWorkRequireAddDTO.setCompanyId(getRandomValue("varchar",32));
        empWorkRequireAddDTO.setRequireType(EmpInfoScene.ENTRY.getValue());
        empWorkRequireAddDTO.setCompany(EmpInfoRequireType.NO_NEED.getValue());
        empWorkRequireAddDTO.setPosition(EmpInfoRequireType.NO_NEED.getValue());
        empWorkRequireAddDTO.setStartTime(EmpInfoRequireType.NO_NEED.getValue());
        empWorkRequireAddDTO.setEndTime(EmpInfoRequireType.NO_NEED.getValue());
        empWorkRequireAddDTO.setLeaveReason(EmpInfoRequireType.NO_NEED.getValue());
        empWorkRequireAddDTO.setWitName(EmpInfoRequireType.NO_NEED.getValue());
        empWorkRequireAddDTO.setWitPhone(EmpInfoRequireType.NO_NEED.getValue());
        return empWorkRequireAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpWorkRequireUpdateDTO
     */
    public EmpWorkRequireUpdateDTO getEmpWorkRequireUpdateDTO(EmpWorkRequireVO empWorkRequireVO){
        return empWorkRequireService.selectDOById(empWorkRequireVO.getId(), SITE_ID).to(EmpWorkRequireUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpWorkRequireQuery
     */
    public EmpWorkRequireQuery getEmpWorkRequireQuery() {
        EmpWorkRequireQuery empWorkRequireQuery = new EmpWorkRequireQuery();
        List<EmpWorkRequireDO> empWorkRequireDOList = empWorkRequireService.list(new EmpWorkRequireDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empWorkRequireDOList)) {
            EmpWorkRequireDO empWorkRequireDO = empWorkRequireDOList.get(0);
            empWorkRequireQuery = empWorkRequireDO.to(EmpWorkRequireQuery.class);
        }
        return empWorkRequireQuery;
    }

    /**
     * 保存示例
     * @return EmpWorkRequireVO
     */
    public EmpWorkRequireVO saveEmpWorkRequireExample(){
        EmpWorkRequireAddDTO addDTO = this.getEmpWorkRequireAddDTO();
        EmpWorkRequireVO empWorkRequireVO = empWorkRequireService.save(addDTO,buildTokenUser());
        return empWorkRequireVO;
    }


}

